/*
 * adc_manual.c
 *
 * Created: 19.03.2013 10:26:22
 *  Author: saenko
 */ 

#include "adc_manual.h"


unsigned char adc_convert(void)
{
	unsigned char adc_data;
	sbi(ADCSRA,ADSC);
	while(bit_is_clear(ADCSRA,ADIF));
	adc_data = ADCH;
	return adc_data;	
}

void adc_change_channel(uint8_t channel)
{
	cbi(ADCSRA,ADEN);
	ADMUX = ADMUX&0b11110000;
	ADMUX = ADMUX|channel;
	sbi(ADCSRA,ADEN);
	adc_convert();
}

void adcm_init(void)
{
	ADMUX = _BV(REFS0)|_BV(ADLAR); //V_REF=AVCC, SHIFTLEFT, CHAN=0

	
	ADCSRA = _BV(ADEN)|_BV(ADPS2)|_BV(ADPS1); //ADC EN, 125KHz@8MHz
	
	DIDR0 = 0;	
	
	DDRC = 0b00000000;
}
